package com.ruoyi.sales.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.sales.domain.ZcPlanCode;
import com.ruoyi.sales.service.IZcPlanCodeService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.sales.domain.ZcSalesList;
import com.ruoyi.sales.service.IZcSalesListService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 销售单Controller
 * 
 * @author woo
 * @date 2024-04-09
 */
@RestController
@RequestMapping("/sales/salesList")
public class ZcSalesListController extends BaseController
{
    @Autowired
    private IZcSalesListService zcSalesListService;
    @Autowired
    private IZcPlanCodeService planCodeService;

    /**
     * 查询销售单列表
     */
    @PreAuthorize("@ss.hasPermi('sales:salesList:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZcSalesList zcSalesList)
    {
        startPage();
        List<ZcSalesList> list = zcSalesListService.selectZcSalesListList(zcSalesList);
        return getDataTable(list);
    }

    /**
     * 导出销售单列表
     */
    @PreAuthorize("@ss.hasPermi('sales:salesList:export')")
    @Log(title = "销售单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZcSalesList zcSalesList)
    {
        List<ZcSalesList> list = zcSalesListService.selectZcSalesListList(zcSalesList);
        ExcelUtil<ZcSalesList> util = new ExcelUtil<ZcSalesList>(ZcSalesList.class);
        util.exportExcel(response, list, "销售单数据");
    }

    /**
     * 获取销售单详细信息
     */
    @PreAuthorize("@ss.hasPermi('sales:salesList:query')")
    @GetMapping(value = "/{salesId}")
    public AjaxResult getInfo(@PathVariable("salesId") Long salesId)
    {
        return success(zcSalesListService.selectZcSalesListBySalesId(salesId));
    }

    /**
     * 新增销售单
     */
    @PreAuthorize("@ss.hasPermi('sales:salesList:add')")
    @Log(title = "销售单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZcSalesList zcSalesList)
    {
        return toAjax(zcSalesListService.insertZcSalesList(zcSalesList));
    }

    /**
     * 修改销售单
     */
    @PreAuthorize("@ss.hasPermi('sales:salesList:edit')")
    @Log(title = "销售单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZcSalesList zcSalesList)
    {
        return toAjax(zcSalesListService.updateZcSalesList(zcSalesList));
    }

    /**
     * 删除销售单
     */
    @PreAuthorize("@ss.hasPermi('sales:salesList:remove')")
    @Log(title = "销售单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{salesIds}")
    public AjaxResult remove(@PathVariable Long[] salesIds)
    {
        return toAjax(zcSalesListService.deleteZcSalesListBySalesIds(salesIds));
    }

    /**
     * 获取计划编码列表
     */
    @PreAuthorize("@ss.hasPermi('sales:salesList:list')")
    @GetMapping("/codeList")
    public AjaxResult codeList(){
        List<ZcPlanCode> planCodeList = planCodeService.selectAllPlanCode();
        for (ZcPlanCode zcPlanCode : planCodeList) {
            zcPlanCode.setCustomText("收货人:"+zcPlanCode.getCustom()+
                    " 收货地址:"+zcPlanCode.getAddress()+
                    " 联系方式"+zcPlanCode.getPhone());
        }
        return success(planCodeList);
    }

    /**
     * 获取销售单列表
     */
    @GetMapping("/salesList")
    public AjaxResult salesList(){
        List<ZcSalesList> salesLists = zcSalesListService.selectAll();
        return success(salesLists);
    }


}
